﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace BlockOS
{
    public static class MathUtil
    {
        public static float SqrtTwoOverTwo = Mathf.Sqrt(2) / 2.0f;

        public static bool IsInCuboid(Vector3Int start, Vector3Int end, Vector3Int position)
        {
            var (xMin, xMax) = (start.x < end.x) ? (start.x, end.x) : (end.x, start.x);
            var (yMin, yMax) = (start.y < end.y) ? (start.y, end.y) : (end.y, start.y);
            var (zMin, zMax) = (start.z < end.z) ? (start.z, end.z) : (end.z, start.z);
            return Between(position.x, xMin, xMax) && Between(position.y, yMin, yMax) && Between(position.z, zMin, zMax);
        }

        public static bool Between(this int num, int min, int max) => num >= min && num < max;

        public static (int, int) FindMinMax(int a, int b) => a < b ? (a, b) : (b, a);

        public static int ManhattanDistance(Vector3Int a, Vector3Int b)
        {
            return Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z);
        }

        public static float ManhattanDistance(Vector3 a, Vector3 b)
        {
            return Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z);
        }

        public static float ManhattanDistance((float x, float y, float z) a, (float x, float y, float z) b)
        {
            return Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z);
        }

        public static float ManhattanDistance(float x0, float y0, float z0, float x1, float y1, float z1)
        {
            return Mathf.Abs(x1 - x0) + Mathf.Abs(y1 - y0) + Mathf.Abs(z1 - z0);
        }
    }
}
